new Vue({
  el: '#app',
  data() {
    return {
      form: {
        // Article_Name: "",
        hotspot: '0',  //0是消息1消息提示
        Type: "0",   //1是自己0是全部
        Row_Status: '',  //空是全部0是未读1是已读2是删除
        token: $.cookie("token"),
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      total: 0,
      flag: true,
      category: [],
      Enterprise: [],
      tableData: [],
      activeName: 'first',
      loading: false,
      Enterprise_Info_SerialNumber: $.cookie("enterprise")
    }
  },
  mounted() {
    //默认查询第一组数据
    this.getList(this.form)
    //查询所有类别
    // this.getCategoryData()
    //查询所有发布过采购的公司
    // this.getEnterpriseData()
  },
  methods: {
    // 切换导航栏
    handleClick(event) {
      // 空是全部0是未读1是已读2是删除
      if (event.index == 0) {
        this.form.Row_Status = ''
        this.getList(this.form)
      } else if (event.index == 1) {
        this.form.Row_Status = 0
        this.getList(this.form)
      } else if (event.index == 2) {
        this.form.Row_Status = 1
        this.getList(this.form)
      }
    },
    //通过关键字查询数据
    onSerach() {
      this.getList(this.form)
    },
    // //通过选择类别查询数据
    // change(e) {
    //   this.form.Category_SerialNumber = e
    //   this.getList(this.form)
    // },
    // //通过选择公司查询数据
    // change1(e) {
    //   this.form.Enterprise_Info_SerialNumber = e
    //   this.getList(this.form)
    // },
    //号码按键查询
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    //号码按键查询
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    //分页查询数据
    getList(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekMessageAllAction',
        success: function (Result) {
          _this.tableData = Result.tableData;
          // _this.tableData.forEach(item => item.loading = false)
          console.log(_this.tableData)
          _this.total = parseInt(Result.limit)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    // 修改状态
    EditAction(row, num, flag) {
      const _this = this
      // row.loading = true
      // console.log(row.loading)
      let detel = {};
      if (flag) {
        _this.flag = false
        $.ajax({
          url: DomainName + '/getInquiryIDOriginal',
          type: 'POST',
          data: {
            Primary_Key_Name: 'Group_Seek_Message_SerialNumber',  //主键名
            Primary_Key: row.Group_Seek_Message_SerialNumber,  //主键值
            Data: 'group_seek_message',
            token: $.cookie("token")
          },
          success: function (res) {
            console.log(res)
            if (res.length == 1) {
              res[0].Row_Status = num
              detel = res[0];
              let data = {
                Data: JSON.stringify({ Modify: { group_seek_message: [detel] }, }),
                token: $.cookie("token")
              };
              $.ajax({
                url: DomainName + '/getEditAction',
                type: 'POST',
                data,
                success: function (res) {
                  if (res.Status === 'success') {
                    // _this.$message.success("更改成功");
                    _this.getList(_this.form);
                  } else {
                    _this.$message.error("操作失败，请稍后再试")
                  }
                },
                error: function () {
                  _this.$message.error("操作失败，请稍后再试")
                },
                complete: function (XMLHttpRequest) {
                  _this.flag = true
                  if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                    window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("Contentpath");
                  }
                },
              })
            }
          }
        })
      }
    },
    //已读消息
    ReadInformation(row, num) {
      this.EditAction(row, num, this.flag)
    },
    // 删除消息
    DeleteInformation(row, num) {
      this.EditAction(row, num, this.flag)
    }
  },
})

